package com.ruoyi.cderp.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cderp.mapper.ProductStoMapper;
import com.ruoyi.cderp.domain.ProductSto;
import com.ruoyi.cderp.service.IProductStoService;

/**
 * 产品库存Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-15
 */
@Service
public class ProductStoServiceImpl implements IProductStoService
{
    @Autowired
    private ProductStoMapper productStoMapper;

    /**
     * 查询产品库存
     *
     * @param id 产品库存主键
     * @return 产品库存
     */
    @Override
    public ProductSto selectProductStoById(String id)
    {
        return productStoMapper.selectProductStoById(id);
    }

    /**
     * 查询产品库存列表
     *
     * @param productSto 产品库存
     * @return 产品库存
     */
    @Override
    public List<ProductSto> selectProductStoList(ProductSto productSto)
    {
        return productStoMapper.selectProductStoList(productSto);
    }

    /**
     * 新增产品库存
     *
     * @param productSto 产品库存
     * @return 结果
     */
    @Override
    public int insertProductSto(ProductSto productSto)
    {
        //随机生成组合商品编号
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String formattedDate = sdf.format(new Date());
        Random random = new Random();
        int randomNumber = 10000000 + random.nextInt(90000000); // 生成8位数随机数
        productSto.setId("110" + formattedDate+randomNumber);
        return productStoMapper.insertProductSto(productSto);
    }

    /**
     * 修改产品库存
     *
     * @param productSto 产品库存
     * @return 结果
     */
    @Override
    public int updateProductSto(ProductSto productSto)
    {
        return productStoMapper.updateProductSto(productSto);
    }

    /**
     * 批量删除产品库存
     *
     * @param ids 需要删除的产品库存主键
     * @return 结果
     */
    @Override
    public int deleteProductStoByIds(String[] ids)
    {
        return productStoMapper.deleteProductStoByIds(ids);
    }

    /**
     * 删除产品库存信息
     *
     * @param id 产品库存主键
     * @return 结果
     */
    @Override
    public int deleteProductStoById(String id)
    {
        return productStoMapper.deleteProductStoById(id);
    }
}
